package Network;

import java.util.Calendar;

/**
 * The creates an instance of a location message from the Ubisense system.
 * This identifies the tags position.
  Copyright (C) 2009 BBC Research, Sam Davies, <Sam.Davies@bbc.co.uk>

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.


 */
public class LocationMessage extends Message {

    private long tag_id_top,  flags,  slot_interval,  slot_delay;
    private float x,  y,  z,  gdop,  error;
    private UbiSenseCoords coords;
/**
 * Creates an instance of a Location Message event from the Ubisense System.
 * 
 * 
 * @param messageType The message type of the tag (0x26A)
 * @param tag_id_top The top id of the tag - currently always 0000
 * @param tag_id_bottom The unique identifier of the tag.
 * @param flags (flags & 1) == 'this is a valid location'
 * @param x The X location of the tag
 * @param y The Y location of the tag
 * @param z The Z location of the tag
 * @param gdop Geometric dilution of precision
 * @param error StdErr of the tags position
 * @param slot Time slot of the tag
 * @param slot_interval Microseconds between two timeslots (a constant for one 
 * instance of the location system)
 * @param slot_delay Delay between the timeslot in which the UWB was transmitted
 * and the timeslot of the message (a constant for one instance of the location 
 * system)
 * @param cell ID of the cell tag is located in.
 */
    public LocationMessage(char messageType, long tag_id_top, long tag_id_bottom, long flags, float x, float y, float z, float gdop, float error, long slot, long slot_interval, long slot_delay, long cell) {
        super(messageType, tag_id_bottom, slot, cell);
        this.tag_id_top = tag_id_top;

        this.flags = flags;
        this.x = x;
        this.y = y;
        this.z = z;
        this.gdop = gdop;
        this.error = error;

        this.slot_interval = slot_interval;
        this.slot_delay = slot_delay;
        String idAsString = ""+tag_id_bottom;
        Calendar cal = Calendar.getInstance();


        this.coords = new UbiSenseCoords(x, y, z, idAsString, cal.HOUR_OF_DAY, cal.MINUTE, cal.SECOND, cal.MILLISECOND, "");

    }

    /**
 * Creates an instance of a Location Message event from the a file, where 
     * Message Type is a string, not char data block.
 * 
 * 
 * @param messageType The message type of the tag (0x26A)
 * @param tag_id_top The top id of the tag - currently always 0000
 * @param tag_id_bottom The unique identifier of the tag.
 * @param flags (flags & 1) == 'this is a valid location'
 * @param x The X location of the tag
 * @param y The Y location of the tag
 * @param z The Z location of the tag
 * @param gdop Geometric dilution of precision
 * @param error StdErr of the tags position
 * @param slot Time slot of the tag
 * @param slot_interval Microseconds between two timeslots (a constant for one 
 * instance of the location system)
 * @param slot_delay Delay between the timeslot in which the UWB was transmitted
 * and the timeslot of the message (a constant for one instance of the location 
 * system)
 * @param cell ID of the cell tag is located in.
 */
    public LocationMessage(String messageType, long tag_id_top, long tag_id_bottom, long flags, float x, float y, float z, float gdop, float error, long slot, long slot_interval, long slot_delay, long cell) {
        super((char)0x26a, tag_id_bottom, slot, cell);
        this.tag_id_top = tag_id_top;

        this.flags = flags;
        this.x = x;
        this.y = y;
        this.z = z;
        this.gdop = gdop;
        this.error = error;

        this.slot_interval = slot_interval;
        this.slot_delay = slot_delay;
        String idAsString = ""+tag_id_bottom;

        this.coords = new UbiSenseCoords(x, y, z, idAsString, "");
    }

    /**
     * @return the tag_id_top
     */
    public long getTag_id_top() {
        return tag_id_top;
    }

    /**
     * @return the flags
     */
    public long getFlags() {
        return flags;
    }

    /**
     * @return the slot_interval
     */
    public long getSlot_interval() {
        return slot_interval;
    }

    /**
     * @return the slot_delay
     */
    public long getSlot_delay() {
        return slot_delay;
    }

    /**
     * @return the x
     */
    public float getX() {
        return x;
    }

    /**
     * @return the y
     */
    public float getY() {
        return y;
    }

    /**
     * @return the z
     */
    public float getZ() {
        return z;
    }

    /**
     * @return the gdop
     */
    public float getGdop() {
        return gdop;
    }

    /**
     * @return the error
     */
    public float getError() {
        return error;
    }

    @Override
    public String toString() {
        return ("Location message. Tag Id; " + this.getTag_id_bottom() + ", flags" + this.getFlags() +
                ", x; " + this.getX() + " y;" + this.getY() + " z; " + this.getZ() + ", gdop; " + this.getGdop() + ", error; " + this.getError() +
                ", slot; " + this.getSlot() + ", slot interval; " + this.getSlot_interval() +
                ", slot delay; " + this.getSlot_delay() + ", cell; " + this.getCell());
    }

    /**
     * @return the coords
     */
    public UbiSenseCoords getCoords() {
        return coords;
    }
}
